const path = require("path");
const ws = require('nodejs-websocket');
const Fs = require("fs");

// 当前使用机器人的总人数
let wsCount = 0;

const wsClient = ws.createServer((res) => {
    // 每出现一个连接即加1
    wsCount++;
    res.on("close", () => {
        // 每次断开连接即减1
        wsCount--;
    })
    res.on("error", () => {});

    res.on("text", str => {
        Fs.readFile(path.join(__dirname, "notice.json"), "utf-8", (err, data) => {
            if (!err) {
                res.sendText(JSON.stringify({
                    type: "notice",
                    data: data
                }));
            }
        })
    })
});

wsClient.listen(10208, () => {
    console.log("Socket is running on port 10208");
})